package com.zh.plus;

import com.alibaba.fastjson.JSONObject;
import com.zh.util.dict.CodeMsg;
import com.zh.vo.Result;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletResponse;
import java.io.OutputStream;

public abstract class BaseInterceptor extends HandlerInterceptorAdapter {

    /**
     *     当拦截器要直接封装response并返回
     */

    void render(HttpServletResponse response, CodeMsg cm) throws Exception {
        response.setContentType("application/json;charset=UTF-8");
        OutputStream out = response.getOutputStream();
        String str  = JSONObject.toJSONString(Result.failure(cm));
        out.write(str.getBytes("UTF-8"));
        out.flush();
        out.close();
    }

}
